package com.luck.easyfoodbatch.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.util.Tools;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LogisticsActivity extends BaseActivity {
    @BindView(R.id.wb)
    WebView wb;
    @BindView(R.id.progress_bar)
    ProgressBar progressBar;
    private String postid = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics, "查看物流", MODE_BACK_NAVIGATION);
        ButterKnife.bind(this);
        String use_ydx = getIntent().getStringExtra("use_ydx");
        if (Tools.isNull(use_ydx)) {
            use_ydx = "0";
        }
        postid = getIntent().getStringExtra("postid");
        wb.getSettings().setDefaultTextEncodingName("utf-8");
        wb.getSettings().setJavaScriptEnabled(true);
        wb.getSettings().setUseWideViewPort(true);
        wb.getSettings().setLoadWithOverviewMode(true);
        wb.getSettings().setGeolocationEnabled(true);
        wb.getSettings().setDomStorageEnabled(true);
        wb.setWebChromeClient(new WebChromeClient());
        wb.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                progressBar.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progressBar.setVisibility(View.GONE);
            }
        });

        //订单列表中use_ydx 1不选择运东西 0选择运东西
        String url = "";
        if (use_ydx.equals("1")) {
            // 不使用运东西 用快递100查询订单
            url = "https://m.kuaidi100.com/index_all.html?postid=" + postid;
        } else {
            url = "https://m.kuaidi100.com/result.jsp?com=yundx&nu=" + postid;
        }
        wb.loadUrl(url);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (wb != null) {
            wb.destroy();
        }
    }
}
